using System.Collections.Generic;
using System.Linq;
using OpenQA.Selenium;

namespace YatFram.Browser.Selenium
{
    public class SeleniumRadioBox : ISingleOption
    {
        private readonly IEnumerable<IWebElement> radioOptions;

        public SeleniumRadioBox(IEnumerable<IWebElement> radioOptions)
        {
            this.radioOptions = radioOptions;
        }

        public string SelectedValue
        {
            get
            {
                var selectedOption = radioOptions.SingleOrDefault(option => option.Selected);
                return selectedOption == null ? null : selectedOption.Value;
            }
        }

        public void Select(string value)
        {
            radioOptions.Single(option => option.Value == value).Selected = true;
        }
    }
}